﻿using System.Collections.Generic;
using System;

namespace Commons.Models.Settings.Matchers
{
	[Serializable]
	public class OrMatcher<T> : IMatcher<T>
	{
		private List<IRule<T>> rules;

		public OrMatcher()
			: this(new List<IRule<T>>())
		{
		}

		public OrMatcher(List<IRule<T>> rules)
		{
			this.rules = rules;
		}

		public bool Met(T target)
		{
			if (target == null)
			{
				return false;
			}

			foreach (IRule<T> rule in rules)
			{
				if (rule.Met(target))
				{
					return true;
				}
			}

			return false;
		}

		public void AddRule(IRule<T> rule)
		{
			rules.Add(rule);
		}
	}
}
